﻿Public Class frm_settings

    Private Sub frm_settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim _tools As New Tools
        Dim _settings_file_path As String
        Dim _settings As New Settings

        _settings_file_path = IO.Path.Combine(Application.StartupPath, "settings.xml")

        If IO.File.Exists(_settings_file_path) Then

            _settings = _tools.XMLDeSerialize(_settings, _settings_file_path)

            txt_default_upper.Text = _settings.GetSetDefaultUpper
            txt_default_desc.Text = _settings.GetSetDefaultDescription
            num_default_max_threads.Value = _settings.GetSetDefaultMaxThreads
            txt_default_password.Text = _settings.GetSetDefaultEncryptPassword
            chk_default_encrypt.Checked = _settings.GetSetDefaultEncryptEnabled



        End If

    End Sub

    Private Sub cmd_save_Click(sender As Object, e As EventArgs) Handles cmd_save.Click

        Dim _tools As New Tools
        Dim _settings_file_path As String
        Dim _settings As New Settings

        Try

            _settings_file_path = IO.Path.Combine(Application.StartupPath, "settings.xml")


            _settings.GetSetDefaultUpper = txt_default_upper.Text
            _settings.GetSetDefaultDescription = txt_default_desc.Text
            _settings.GetSetDefaultMaxThreads = num_default_max_threads.Value
            _settings.GetSetDefaultEncryptPassword = txt_default_password.Text
            _settings.GetSetDefaultEncryptEnabled = chk_default_encrypt.Checked

            _tools.XMLSerialize(_settings, _settings_file_path)

            MessageBox.Show("Einstellungen erfolgreich gespeichert!", "Einstellungen gespeichert!", MessageBoxButtons.OK, MessageBoxIcon.Information)

            Me.Close()


        Catch ex As Exception
            MessageBox.Show("Fehler beim speichern der Einstellungen!", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Sub
End Class